﻿#include "FITKAcousticsSEAJunctionMgrAdaptor.h"
#include"FITK_Component/FITKAcousticsModel/FITKSEAAbstractJunction.h"
#include"FITK_Component/FITKAcousticsModel/FITKAbstractJunction.h"
#include"FITK_Component/FITKAcousticsModel/FITKSEAJunctionLine.h"
#include"FITK_Component/FITKAcousticsModel/FITKSEAJunctionPoint.h"
#include"FITK_Component/FITKAcousticsModel/FITKSEAJunctionArea.h"
#include "FITKAcousticsHDF5Writer.h"
#include "FITKAcousticsHDF5Reader.h"
#include "FITK_Interface/FITKInterfaceIO/FITKHDF5FileTool.h"

IO::FITKAcousticsSEAJunctionMgrAdaptor::FITKAcousticsSEAJunctionMgrAdaptor()
{
    this->m_JunUserDefStrType = this->createJunUserDefStrType();//创建JunUserDefStr自定义类型
    this->m_JunPointConStrType = this->createJunPointConStrType();//创建JunPointConStr自定义类型
    this->m_JunLineConStrType = this->createJunLineConStrType();//创建JunLineConStr自定义类型
    this->m_JunAreaConStrType = this->createJunAreaConStrType();//创建JunAreaConStr自定义类型
}
bool IO::FITKAcousticsSEAJunctionMgrAdaptor::adaptR()
{
    
    if (m_JunctionManagerP == nullptr || _reader == nullptr) return false;
    m_toolp = _reader->getHDF5FileTool();//初始化工具

    std::tuple<bool, H5::Group>Ret = m_toolp->openGp("Junction");//创建连接组
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group gp = std::get<1>(Ret);

    std::tuple<bool, H5::Attribute>RetAttr = m_toolp->openAttribut(gp, "JunctionCount"); //打开组个数属性
    if (std::get<0>(RetAttr) == false) { return false; }
    H5::Attribute CountAttrattr = std::get<1>(RetAttr);
    int count = -1;
    CountAttrattr.read(H5::PredType::NATIVE_INT, &count);



    for (int i = 0; i < count; i++)
    {
        QString number = QString::number(i);
        std::tuple<bool, H5::Group>Ret = m_toolp->openGp(gp, number.toStdString().data());//打开子节点
        if (std::get<0>(Ret) == false) { return false; }
        H5::Group subGroup = std::get<1>(Ret);
        std::string JunctionType = "";
        m_toolp->readGroupStr(subGroup, "JunctionType", JunctionType);
        if (JunctionType == "JunctionPoint")
        {
            this->readJunctionPoint(subGroup, m_JunctionManagerP);
        }
        
        if (JunctionType == "JunctionLine")
        {
            this->readJunctionLine(subGroup, m_JunctionManagerP);
        }
        if (JunctionType == "JunctionArea")
        {
            this->readJunctionArea(subGroup, m_JunctionManagerP);
        }

    }
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::adaptW()
{
    if (m_JunctionManagerP == nullptr || _writer == nullptr) return false;
    m_toolp = _writer->getHDF5FileTool();//初始化工具

    std::tuple<bool, H5::Group> Ret = m_toolp->createGp("Junction");     //创建连接组
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group gp = std::get<1>(Ret);

    int DataCount = m_JunctionManagerP->getDataCount();//管理器所管理的所有数据
    m_toolp->createAttribute(gp, "JunctionCount", DataCount);
    for (int i = 0; i < DataCount; ++i)
    {
        //根据index获取数据
        Acoustics::FITKAbstractJunction*JunctionP = m_JunctionManagerP->getDataByIndex(i);

        QString number = QString::number(i);
        std::tuple<bool, H5::Group>Ret = m_toolp->createGp(gp, number.toStdString().data());//创建子节点
        if (std::get<0>(Ret) == false) { return false; }
        H5::Group subGroup = std::get<1>(Ret);


        if (JunctionP == nullptr)
        {
            return false;
        }
        Acoustics::FITKAbstractJunction::JunctionType junctionType = JunctionP->getJunctiontType();//耦合对象类型
        switch (junctionType)
        {
        case Acoustics::FITKAbstractJunction::NoneJunction:
            break;
        case Acoustics::FITKAbstractJunction::SEAPointJunction:
        {
            Acoustics::FITKSEAJunctionPoint *subP = dynamic_cast<Acoustics::FITKSEAJunctionPoint*>(JunctionP);
            if (subP == nullptr) { return false; }
            this->writeJunctionPoint(subGroup, subP);//写点连接数据
            break;
        }
        case Acoustics::FITKAbstractJunction::SEALineJunction:
        {
            Acoustics::FITKSEAJunctionLine *subP = dynamic_cast<Acoustics::FITKSEAJunctionLine*>(JunctionP);
            if (subP == nullptr) { return false; }
            this->writeJunctionLine(subGroup, subP);//写线连接数据
            break;
        }
        case Acoustics::FITKAbstractJunction::SEAAreaJunction:
        {
            Acoustics::FITKSEAJunctionArea *subP = dynamic_cast<Acoustics::FITKSEAJunctionArea*>(JunctionP);
            if (subP == nullptr) { return false; }
            this->writeJunctionArea(subGroup, subP);//写面连接数据
            break;
        }
        default:
            break;
        }
    }

    return true;
}

void IO::FITKAcousticsSEAJunctionMgrAdaptor::setData(Acoustics::FITKJunctionManager * JunctionManagerP)
{
    if (JunctionManagerP == nullptr)
    {
        return;
    }
    m_JunctionManagerP = JunctionManagerP;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::writeJunctionPoint(H5::Group & gp, Acoustics::FITKSEAJunctionPoint * subP)
{
    if (subP == nullptr)
    {
        return false;
    }
    //写父类数据
    this->writeDataObjectAndJunction(gp, subP);

    //FITKSEAJunctionPoint数据
    int PointID = subP->getPointID();//点ID
    QList<Acoustics::FITKSEAJunPointConStr> Connections = subP->getConnections();//连接信息

    m_toolp->writeCustomtypesOnedim(gp, "JunPointConStr", this->m_JunPointConStrType,
        Connections.toVector().data(), Connections.toVector().size());

    m_toolp->writeGroupAttrInt(gp, "PointID", PointID);
    m_toolp->writeGroupAttrStr(gp, "JunctionType", "JunctionPoint");//写出类型
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::readJunctionPoint(H5::Group & gp, Acoustics::FITKJunctionManager * mager)
{
    if (mager == nullptr)
    {
        return false;
    }
    Acoustics::FITKSEAJunctionPoint * subP = new Acoustics::FITKSEAJunctionPoint;
    if (subP == nullptr)
    {
        return false;
    }
    this->readDataObjectAndJunction(gp, subP);//读父类数据

    //FITKSEAJunctionPoint数据
    int PointID = -1;//点ID
    std::vector<Acoustics::FITKSEAJunPointConStr>Connections;
    m_toolp->readCustomtypesOnedim<Acoustics::FITKSEAJunPointConStr>(gp, "JunPointConStr", this->m_JunPointConStrType, Connections);

    m_toolp->readGroupint(gp, "PointID", &PointID);
    subP->setPointID(PointID);
    for (int i = 0; i < Connections.size(); i++)
    {
        subP->appendConnection(Connections.at(i));
    }
    mager->appendDataObj(subP);

    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::writeJunctionLine(H5::Group & gp, Acoustics::FITKSEAJunctionLine * subP)
{
    if (subP == nullptr)
    {
        return false;
    }
    Acoustics::FITKSEAAbstractJunction * parentP = dynamic_cast<Acoustics::FITKSEAAbstractJunction*>(subP);
    if (parentP == nullptr)
    {
        return false;
    }

    //写父类数据
    this->writeDataObjectAndJunction(gp, parentP);


    //FITKSEAJunctionLine本类数据
    double length = subP->getLineLength();//线长度
    QList<int>Points = subP->getPoints();//所有点ID
    QList<Acoustics::FITKSEAJunLineConStr> Connections = subP->getConnections();//所有连接信息

    m_toolp->writeCustomtypesOnedim(gp, "JunLineConStr", this->m_JunLineConStrType,
        Connections.toVector().data(), Connections.toVector().size());

    std::vector<int> PointsVt = Points.toVector().toStdVector();
    m_toolp->CreateOneDarrayDataSetInt(gp, "Points", PointsVt);

    m_toolp->writeGroupAttrDouble(gp, "length", length);
    m_toolp->writeGroupAttrStr(gp, "JunctionType", "JunctionLine");//写出类型

    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::readJunctionLine(H5::Group & gp, Acoustics::FITKJunctionManager * mager)
{
    if (mager == nullptr)
    {
        return false;
    }
    Acoustics::FITKSEAJunctionLine * subP = new Acoustics::FITKSEAJunctionLine;
    if (subP == nullptr)
    {
        return false;
    }

    this->readDataObjectAndJunction(gp, subP);//读父类数据


    //读本类FITKSEAJunctionLine数据
    double length = 0.0;//线长度

    std::vector<Acoustics::FITKSEAJunLineConStr>Connections;
    m_toolp->readCustomtypesOnedim<Acoustics::FITKSEAJunLineConStr>(gp, "JunLineConStr", this->m_JunLineConStrType, Connections);

    std::vector<int> PointsVt = {};
    m_toolp->ReadOneDArrayDataSetInt(gp, "Points", PointsVt);

    m_toolp->readGroupDouble(gp, "length", &length);

    //添加连接信息
    for (int i = 0; i < Connections.size(); ++i)
    {
        subP->appendConnection(Connections.at(i));
    }
    //添加点ID
    for (int i = 0; i < PointsVt.size(); ++i)
    {
        subP->appendPoint(PointsVt.at(i));
    }
    //设置线长度
    subP->setLineLength(length);

    mager->appendDataObj(subP);
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::writeJunctionArea(H5::Group & gp, Acoustics::FITKSEAJunctionArea * subP)
{
    if (subP == nullptr)
    {
        return false;
    }
    Acoustics::FITKSEAAbstractJunction * parentP = dynamic_cast<Acoustics::FITKSEAAbstractJunction*>(subP);
    if (parentP == nullptr)
    {
        return false;
    }

    //写父类数据
    this->writeDataObjectAndJunction(gp, parentP);

    //FITKSEAJunctionArea本类数据
    bool IsUseResonant = subP->getIsUseResonant();// 是否使用共振
    m_toolp->writeGroupAttrBool(gp, "IsUseResonant", IsUseResonant);

    bool IsUseNonresonant = subP->getIsUseNonresonant();//是否使用非共振
    m_toolp->writeGroupAttrBool(gp, "IsUseNonresonant", IsUseNonresonant);


    bool IsUseLeak = subP->getIsUseLeak();//是否使用泄漏
    m_toolp->writeGroupAttrBool(gp, "IsUseLeak", IsUseLeak);

    bool IsUseTransmissionLoss = subP->getIsUseTransmissionLoss();// 是否使用传输损耗
    m_toolp->writeGroupAttrBool(gp, "IsUseTransmissionLoss", IsUseTransmissionLoss);


    int Spectrum = subP->getSpectrum();//传输损耗频谱
    m_toolp->writeGroupAttrInt(gp, "Spectrum", Spectrum);

    Acoustics::FITKSEAJunctionArea::JunctionAreaDirection Direction = subP->getDirection();//方向
    switch (Direction)
    {
    case Acoustics::FITKSEAJunctionArea::From:
    {
        m_toolp->writeGroupAttrStr(gp, "Direction", "From");
        break;
    }

    case Acoustics::FITKSEAJunctionArea::To:
    {
        m_toolp->writeGroupAttrStr(gp, "Direction", "To");
        break;
    }
    default:
        break;
    }

    double AcousticCouplingAreaX = subP->getAcousticCouplingAreaX();//耦合区域倍数
    m_toolp->writeGroupAttrDouble(gp, "AcousticCouplingAreaX", AcousticCouplingAreaX);

    double AcousticRadiationAreaX = subP->getAcousticRadiationAreaX();//辐射区域倍数
    m_toolp->writeGroupAttrDouble(gp, "AcousticRadiationAreaX", AcousticRadiationAreaX);

    double AcousticRadiationPerimaterX = subP->getAcousticRadiationPerimaterX();//辐射周长倍数
    m_toolp->writeGroupAttrDouble(gp, "AcousticRadiationPerimaterX", AcousticRadiationPerimaterX);

    QList<Acoustics::FITKSEAJunAreaConStr> Connections = subP->getConnections();//连接信息
    m_toolp->writeCustomtypesOnedim(gp, "JunAreaConStr", this->m_JunAreaConStrType, Connections.toVector().data(), Connections.toVector().size());
   

    QList<Acoustics::FITKSEAJunAreaLeakStr> Leaks = subP->getLeaks();//渗透数据

    this->writeJunAreaLeakStr(gp, Leaks);

    m_toolp->writeGroupAttrStr(gp, "JunctionType", "JunctionArea");//写出类型
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::readJunctionArea(H5::Group & gp, Acoustics::FITKJunctionManager * mager)
{
    if (mager == nullptr)
    {
        return false;
    }
    Acoustics::FITKSEAJunctionArea * subP = new Acoustics::FITKSEAJunctionArea;
    if (subP == nullptr)
    {
        return false;
    }

    this->readDataObjectAndJunction(gp, subP);//读父类数据

    //FITKSEAJunctionArea本类数据
    
    bool IsUseResonant = false;// 是否使用共振
    m_toolp->readGroupBool(gp, "IsUseResonant", &IsUseResonant);
    subP->setIsUseResonant(IsUseResonant);

    bool IsUseNonresonant = false;//是否使用非共振
    m_toolp->readGroupBool(gp, "IsUseNonresonant", &IsUseNonresonant);
    subP->setIsUseNonresonant(IsUseNonresonant);

    bool IsUseLeak = false;//是否使用泄漏
    m_toolp->readGroupBool(gp, "IsUseLeak", &IsUseLeak);
    subP->setIsUseLeak(IsUseLeak);


    bool IsUseTransmissionLoss = false;// 是否使用传输损耗
    m_toolp->readGroupBool(gp, "IsUseTransmissionLoss", &IsUseTransmissionLoss);
    subP->setIsUseTransmissionLoss(IsUseTransmissionLoss);

    int Spectrum = -1;//传输损耗频谱
    m_toolp->readGroupint(gp, "Spectrum", &Spectrum);
    subP->setSpectrum(Spectrum);


    Acoustics::FITKSEAJunctionArea::JunctionAreaDirection Direction;//方向
    std::string DirectionStr;
    m_toolp->readGroupStr(gp, "Direction", DirectionStr);
    if (DirectionStr== "From")
    {
        subP->setDirection(Acoustics::FITKSEAJunctionArea::JunctionAreaDirection::From);
    }
    else if(DirectionStr == "To")
    {
        subP->setDirection(Acoustics::FITKSEAJunctionArea::JunctionAreaDirection::To);
    }
    else
    {
        return false;
    }

    double AcousticCouplingAreaX = 0.0;//耦合区域倍数
    m_toolp->readGroupDouble(gp, "AcousticCouplingAreaX", &AcousticCouplingAreaX);
    subP->setAcousticCouplingAreaX(AcousticCouplingAreaX);

    double AcousticRadiationAreaX = 0.0;//辐射区域倍数
    m_toolp->readGroupDouble(gp, "AcousticRadiationAreaX", &AcousticRadiationAreaX);
    subP->setAcousticRadiationAreaX(AcousticRadiationAreaX);

    double AcousticRadiationPerimaterX = 0.0;//辐射周长倍数
    m_toolp->readGroupDouble(gp, "AcousticRadiationPerimaterX", &AcousticRadiationPerimaterX);
    subP->setAcousticRadiationPerimaterX(AcousticRadiationPerimaterX);


    std::vector<Acoustics::FITKSEAJunAreaConStr>Connections;
    m_toolp->readCustomtypesOnedim<Acoustics::FITKSEAJunAreaConStr>(gp, "JunAreaConStr", this->m_JunAreaConStrType, Connections);
    for (int i = 0; i < Connections.size(); ++i)
    {
        subP->appendConnection(Connections.at(i));
    }

    QList<Acoustics::FITKSEAJunAreaLeakStr> Leaks = subP->getLeaks();//渗透数据
    this->readJunAreaLeakStr(gp, Leaks);
    subP->replaceLeaks(Leaks);
    mager->appendDataObj(subP);
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::writeJunAreaLeakStr(H5::Group & gp, QList<Acoustics::FITKSEAJunAreaLeakStr> &Leaks)
{
    m_toolp->createAttribute(gp, "JunAreaLeakStrCount", Leaks.size());//写出渗透个数


    for (int i = 0; i < Leaks.size(); ++i)
    {

        QString number = QString::number(i);
        std::tuple<bool, H5::Group>Ret = m_toolp->createGp(gp, number.toStdString().data());//创建子节点
        if (std::get<0>(Ret) == false) { return false; }
        H5::Group subGroup = std::get<1>(Ret);

        QString _name=Leaks.at(i)._name;//名称
        Acoustics::FITKSEAJunAreaLeakStr::LeakType _type= Leaks.at(i)._type;//渗漏类型

        m_toolp->CheckString(_name);
        m_toolp->writeGroupAttrStr(subGroup, "_name", _name.toStdString());
        m_toolp->writeGroupAttrBool(subGroup, "_isEnabled", Leaks.at(i)._isEnabled);//渗漏是否有效
        m_toolp->writeGroupAttrBool(subGroup, "_isLength", Leaks.at(i)._isLength);//长是否可用
        m_toolp->writeGroupAttrDouble(subGroup, "_length", Leaks.at(i)._length);//长
        m_toolp->writeGroupAttrBool(subGroup, "_isWidth", Leaks.at(i)._isWidth);//宽是否可用
        m_toolp->writeGroupAttrDouble(subGroup, "_width", Leaks.at(i)._width);//宽
        m_toolp->writeGroupAttrBool(subGroup, "_isRadius", Leaks.at(i)._width);//半径是否可用
        m_toolp->writeGroupAttrDouble(subGroup, "_radius", Leaks.at(i)._radius);//半径
        m_toolp->writeGroupAttrBool(subGroup, "_isDepth", Leaks.at(i)._isDepth);//深度是否可用
        m_toolp->writeGroupAttrBool(subGroup, "_isArea", Leaks.at(i)._isArea);//区域是否可用
        m_toolp->writeGroupAttrDouble(subGroup, "_area", Leaks.at(i)._area);//区域
        m_toolp->writeGroupAttrBool(subGroup, "_isTLSpectrumID", Leaks.at(i)._isTLSpectrumID);//频谱id是否可用
        m_toolp->writeGroupAttrInt(subGroup, "_TLSpectrumID", Leaks.at(i)._TLSpectrumID);//频谱id

        QString type = "";
        switch (_type)
        {
        case Acoustics::FITKSEAJunAreaLeakStr::Rectangular:
        {
            type = "Rectangular";
            break;
        }
        case Acoustics::FITKSEAJunAreaLeakStr::Circular:
            type = "Circular";
            break;
        case Acoustics::FITKSEAJunAreaLeakStr::Slit:
            type = "Slit";
            break;
        case Acoustics::FITKSEAJunAreaLeakStr::UserDefined:
            type = "UserDefined";
            break;
        default:
            return false;
            break;
        }
        m_toolp->writeGroupAttrStr(subGroup, "type", type.toStdString());//渗漏类型
    }
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::readJunAreaLeakStr(H5::Group & gp, QList<Acoustics::FITKSEAJunAreaLeakStr>& data)
{
    std::tuple<bool, H5::Attribute>RetAttr = m_toolp->openAttribut(gp, "JunAreaLeakStrCount"); //打开组个数属性
    if (std::get<0>(RetAttr) == false) { return false; }
    H5::Attribute CountAttrattr = std::get<1>(RetAttr);
    int count = -1;
    CountAttrattr.read(H5::PredType::NATIVE_INT, &count);


    for (int i = 0; i < count; ++i)
    {
        Acoustics::FITKSEAJunAreaLeakStr temp;

        QString number = QString::number(i);
        std::tuple<bool, H5::Group>Ret = m_toolp->openGp(gp, number.toStdString().data());//打开子节点
        if (std::get<0>(Ret) == false) { return false; }
        H5::Group subGroup = std::get<1>(Ret);



        std::string _name ="";//名称
        m_toolp->readGroupStr(subGroup, "_name", _name);
        QString _QNamm = QString::fromStdString(_name);
        m_toolp->RestoreString(_QNamm);
        temp._name = _QNamm;

        bool _isEnabled = false;
        m_toolp->readGroupBool(subGroup, "_isEnabled", &_isEnabled);//渗漏是否有效
        temp._isEnabled = _isEnabled;

        bool _isLength = false;
        m_toolp->readGroupBool(subGroup, "_isLength", &_isLength);//长是否可用
        temp._isLength = _isLength;

        double _length = 0.0;
        m_toolp->readGroupDouble(subGroup, "_length", &_length);//长
        temp._length = _length;


        bool _isWidth = false;
        m_toolp->readGroupBool(subGroup, "_isWidth", &_isWidth);//宽是否可用
        temp._isWidth = _isWidth;

        double _width = 0.0;
        m_toolp->readGroupDouble(subGroup, "_width", &_width);//宽
        temp._width = _width;

        bool _isRadius = false;
        m_toolp->readGroupBool(subGroup, "_isRadius", &_isRadius);//半径是否可用
        temp._isRadius = _isRadius;

        double _radius = 0.0;
        m_toolp->readGroupDouble(subGroup, "_radius", &_radius);//半径
        temp._radius = _radius;

        bool _isDepth = false;
        m_toolp->readGroupBool(subGroup, "_isDepth", &_isDepth);//深度是否可用
        temp._isDepth = _isDepth;

        bool _isArea = false;
        m_toolp->readGroupBool(subGroup, "_isArea", &_isArea);//区域是否可用
        temp._isArea = _isArea;

        double _area = 0.0;
        m_toolp->readGroupDouble(subGroup, "_area", &_area);//区域
        temp._area = _area;

        bool _isTLSpectrumID = false;
        m_toolp->readGroupBool(subGroup, "_isTLSpectrumID", &_isTLSpectrumID);//频谱id是否可用
        temp._isTLSpectrumID = _isTLSpectrumID;

        int _TLSpectrumID = -1;
        m_toolp->readGroupint(subGroup, "_TLSpectrumID", &_TLSpectrumID);//频谱id
        temp._TLSpectrumID = _TLSpectrumID;

        std::string type = "";

        m_toolp->readGroupStr(subGroup, "type", type);//渗漏类型
        if (type== "Rectangular")
        {
            temp._type = Acoustics::FITKSEAJunAreaLeakStr::Rectangular;
        }
        else if (type == "Circular")
        {
            temp._type = Acoustics::FITKSEAJunAreaLeakStr::Circular;
        }
        else if (type == "Slit")
        {
            temp._type = Acoustics::FITKSEAJunAreaLeakStr::Slit;
        }
        else if (type == "UserDefined")
        {
            temp._type = Acoustics::FITKSEAJunAreaLeakStr::UserDefined;
        }
        else
        {
            return false;
        }
        data.push_back(temp);
    }
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::writeDataObjectAndJunction(H5::Group &gp, Acoustics::FITKSEAAbstractJunction * baseP)
{
    if (baseP == nullptr)
    {
        return false;
    }

    //FITKAbstractNDataObject与FITKAbstractDataObject
    QString DataObjectName = baseP->getDataObjectName();//数据名称
    int DataObjectID = baseP->getDataObjectID();//数据ID

    m_toolp->writeGroupAttrStr(gp, "DataObjectName", DataObjectName.toStdString());
    m_toolp->writeGroupAttrInt(gp, "DataObjectID", DataObjectID);


    //FITKSEAAbstractJunction数据
    QString MatrixForm = baseP->getMatrixForm();//对称矩阵
    QList<Acoustics::FITKSEAJunUserDefStr> UserDefs = baseP->getUserDefs();//自定义信息
    m_toolp->writeCustomtypesOnedim(gp, "JunUserDefStr", m_JunUserDefStrType, UserDefs.toVector().data(), UserDefs.toVector().size());

    bool EnabledJunction = baseP->getEnabledJunction();//是否启用连接

    m_toolp->writeGroupAttrStr(gp, "MatrixForm", MatrixForm.toStdString());
    m_toolp->writeGroupAttrInt(gp, "EnabledJunction", EnabledJunction == true ? 1 : 0);
    return true;
}

bool IO::FITKAcousticsSEAJunctionMgrAdaptor::readDataObjectAndJunction(H5::Group & gp, Acoustics::FITKSEAAbstractJunction * baseP)
{
    if (baseP == nullptr)
    {
        return false;
    }
    //FITKAbstractNDataObject与FITKAbstractDataObject
    std::string DataObjectName = "";//数据名称
    int DataObjectID = -1;//数据ID

    m_toolp->readGroupStr(gp, "DataObjectName", DataObjectName);
    m_toolp->readGroupint(gp, "DataObjectID", &DataObjectID);

    baseP->setDataObjectName(QString::fromStdString(DataObjectName));
    Core::FITKAbstractDataIDAlter a;
    a.modifyDataID(baseP, DataObjectID);

    //FITKSEAAbstractJunction数据
    std::string MatrixForm = "";//对称矩阵
    std::vector<Acoustics::FITKSEAJunUserDefStr>UserDefsVec;
    m_toolp->readCustomtypesOnedim<Acoustics::FITKSEAJunUserDefStr>(gp, "JunUserDefStr", m_JunUserDefStrType, UserDefsVec);
    for (int i = 0; i < UserDefsVec.size(); ++i)
    {
        baseP->appendUserDef(UserDefsVec.at(i));
    }

    int EnabledJunction = false;//是否启用连接

    m_toolp->readGroupStr(gp, "MatrixForm", MatrixForm);
    m_toolp->readGroupint(gp, "EnabledJunction", &EnabledJunction);

    baseP->setEnabledJunction(EnabledJunction == 1 ? true : false);
    baseP->setMatrixForm(QString::fromStdString(MatrixForm));

    return true;
}


H5::CompType IO::FITKAcousticsSEAJunctionMgrAdaptor::createJunUserDefStrType()
{
    //构建自定义类型
    H5::CompType mtype(sizeof(Acoustics::FITKSEAJunUserDefStr));
    mtype.insertMember("_subsysRowID", HOFFSET(Acoustics::FITKSEAJunUserDefStr, _subsysRowID), H5::PredType::NATIVE_INT);
    mtype.insertMember("_subsysColumnID", HOFFSET(Acoustics::FITKSEAJunUserDefStr, _subsysColumnID), H5::PredType::NATIVE_INT);
    mtype.insertMember("_subsysRowIndex", HOFFSET(Acoustics::FITKSEAJunUserDefStr, _subsysRowIndex), H5::PredType::NATIVE_INT);
    mtype.insertMember("_subsysColumnIndex", HOFFSET(Acoustics::FITKSEAJunUserDefStr, _subsysColumnIndex), H5::PredType::NATIVE_INT);
    mtype.insertMember("_spectrumID", HOFFSET(Acoustics::FITKSEAJunUserDefStr, _spectrumID), H5::PredType::NATIVE_INT);
    mtype.insertMember("_rowIndex", HOFFSET(Acoustics::FITKSEAJunUserDefStr, _rowIndex), H5::PredType::NATIVE_INT);
    mtype.insertMember("_columnIndex", HOFFSET(Acoustics::FITKSEAJunUserDefStr, _columnIndex), H5::PredType::NATIVE_INT);
    return mtype;
}

H5::CompType IO::FITKAcousticsSEAJunctionMgrAdaptor::createJunPointConStrType()
{
    // 创建自定义的 HDF5 数据类型
    H5::CompType customType(sizeof(Acoustics::FITKSEAJunPointConStr));

    // 插入成员
    customType.insertMember("_subSysID", HOFFSET(Acoustics::FITKSEAJunPointConStr, _subSysID), H5::PredType::NATIVE_INT);
    customType.insertMember("_radius", HOFFSET(Acoustics::FITKSEAJunPointConStr, _radius), H5::PredType::NATIVE_DOUBLE);
    customType.insertMember("_isAlphaOve", HOFFSET(Acoustics::FITKSEAJunPointConStr, _isAlphaOve), H5::PredType::NATIVE_HBOOL);
    customType.insertMember("_alpha", HOFFSET(Acoustics::FITKSEAJunPointConStr, _alpha), H5::PredType::NATIVE_DOUBLE);
    customType.insertMember("_pointID", HOFFSET(Acoustics::FITKSEAJunPointConStr, _pointID), H5::PredType::NATIVE_INT);
    return customType;
}

H5::CompType IO::FITKAcousticsSEAJunctionMgrAdaptor::createJunLineConStrType()
{
    // 创建自定义的 HDF5 数据类型
    H5::CompType customType(sizeof(Acoustics::FITKSEAJunLineConStr));

    // 插入成员
    customType.insertMember("_subSysID", HOFFSET(Acoustics::FITKSEAJunLineConStr, _subSysID), H5::PredType::NATIVE_INT);
    customType.insertMember("_isAlphaOve", HOFFSET(Acoustics::FITKSEAJunLineConStr, _isAlphaOve), H5::PredType::NATIVE_HBOOL);
    customType.insertMember("_alpha", HOFFSET(Acoustics::FITKSEAJunLineConStr, _alpha), H5::PredType::NATIVE_DOUBLE);
    return customType;
}

H5::CompType IO::FITKAcousticsSEAJunctionMgrAdaptor::createJunAreaConStrType()
{
    // 创建自定义的 HDF5 数据类型
    H5::CompType customType(sizeof(Acoustics::FITKSEAJunAreaConStr));

    // 插入成员
    customType.insertMember("_subSysID", HOFFSET(Acoustics::FITKSEAJunLineConStr, _subSysID), H5::PredType::NATIVE_INT);
    return customType;
}

